package ljx;

import javax.jms.Session;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class loginservlet extends HttpServlet {
    private String myusername=null;
    private String mypassword=null;
    @Override
    public void init(ServletConfig config) throws ServletException {
        myusername=config.getInitParameter("username");
        mypassword=config.getInitParameter("password");
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            String username=req.getParameter("username");
            String password=req.getParameter("password");
            if (username.equals(myusername)&&password.equals(mypassword)){
                HttpSession session = req.getSession();
                session.setAttribute("username",username);
                req.getRequestDispatcher("welcome.jsp").forward(req,resp);
            }
            else {
                resp.sendRedirect("login.jsp");
            }
    }
}
